#include "people_id_file.h"
#include <iostream>

int main() {
    // 指定患者文件夹所在的目录
    std::string directory = "/opt/patient/";

    // 创建 PatientManager 对象
    PatientManager manager(directory);

    // 添加患者信息到缓冲区
    PeopleInfo patient1 = {1, "李华", "黑龙江"};
    PeopleInfo patient2 = {2, "张伟", "四川"};
    PeopleInfo patient3 = {3, "王强", "浙江"};

    manager.addPatient(patient1);
    manager.addPatient(patient2);
    manager.addPatient(patient3);

    // 将缓冲区的所有患者信息写入文件夹
    manager.saveAllPatients();
    std::cout << "Patient information saved to folder." << std::endl;

    // 更新患者信息（重新读取文件夹中的数据）
    manager.update();

    // 查找并打印患者信息
    std::cout << "\nSearching for patients:\n";

    // 根据 ID 查找患者
    if (auto patient = manager.findById(1)) {
        std::cout << "Found patient with ID 1: "
                  << patient->get().name << ", "
                  << patient->get().region << std::endl;
    } else {
        std::cout << "Patient with ID 1 not found." << std::endl;
    }

    // 根据 Name 查找患者
    if (auto patient = manager.findByName("王强")) {
        std::cout << "Found patient with name '王强': "
                  << patient->get().id << ", "
                  << patient->get().region << std::endl;
    } else {
        std::cout << "Patient with name '王强' not found." << std::endl;
    }

    // 打印所有患者信息
    std::cout << "\nAll patients:\n";
    manager.update(); // 确保数据是最新的
    for (const auto& patient : manager.getAllPatients()) {
        std::cout << "ID: " << patient.id
                  << ", Name: " << patient.name
                  << ", Region: " << patient.region << std::endl;
    }

    return 0;
}

